package se.boliang.array;

public class InsertionSort {

	/**
	 * @param args0 A string that will be sorted from small to large
	 */
	public static void main(String[] args) {

		String inputString = args[0]; 
		System.out.println(inputString); 
		
		// convert input string into character array
		char[] inputChar = inputString.toCharArray(); 
		
		// loop through all characters in array
		for (int i = 0 ; i < inputChar.length ; i ++) {
			int j = i; 
			// if the left char is greater than current one
			// it will swap them
			while ( j > 0 && inputChar[j-1] > inputChar[j]) {
				char tempChar = inputChar[j-1]; 
				inputChar[j-1] = inputChar[j]; 
				inputChar[j] = tempChar; 
				j --; 
			}

		}
		for (int i = 0; i < inputChar.length ; i++) {
			System.out.print(inputChar[i]); 			
		}
		

	}

}
